package com.hp.jdoss.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;

/**
* 设置文件上传的大小
*
* @author dongxing
**/
@Configuration
@ConfigurationProperties(prefix = "upload.file")
@Data
public class FileUploadConfig {

    private String maxSize;
    private String requestSize;

    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //文件最大
        factory.setMaxFileSize(DataSize.parse(maxSize)); //KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize(DataSize.parse(requestSize));
        return factory.createMultipartConfig();
    }
}
